package com.d3works.apps.supplychain.service.config;

import com.d3works.apps.account.db.Account;
import com.d3works.apps.account.db.AccountConfig;
import com.d3works.apps.account.service.config.AccountConfigService;
import com.d3works.apps.supplychain.exception.SupplychainExceptionMessage;
import com.d3works.exception.D3worksException;
import com.d3works.exception.db.repo.TraceBackRepository;
import com.d3works.i18n.I18n;
import com.google.inject.servlet.RequestScoped;

@RequestScoped
public class AccountConfigSupplychainService extends AccountConfigService {

  public Account getForecastedInvCustAccount(AccountConfig accountConfig) throws D3worksException {
    if (accountConfig.getForecastedInvCustAccount() == null) {
      throw new D3worksException(
          accountConfig,
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(SupplychainExceptionMessage.FORECASTED_INVOICE_CUSTOMER_ACCOUNT),
          accountConfig.getCompany().getName());
    }
    return accountConfig.getForecastedInvCustAccount();
  }

  public Account getForecastedInvSuppAccount(AccountConfig accountConfig) throws D3worksException {
    if (accountConfig.getForecastedInvSuppAccount() == null) {
      throw new D3worksException(
          accountConfig,
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(SupplychainExceptionMessage.FORECASTED_INVOICE_SUPPLIER_ACCOUNT),
          accountConfig.getCompany().getName());
    }
    return accountConfig.getForecastedInvSuppAccount();
  }
}
